iT邦幫忙

0

Gitlab-delete commit history

  • 分享至 

  • xImage
  •  

This article will teach how to delete the commit history on Gitlab.

Step 1: remove all history (Make sure you have backup, this cannot be reverted)

rm -rf .git

Step 2: reconstruct the Git repo with only the current content.

git init
git add .
git commit -m "Initial commit"

Step 3: push to GitHub.

git remote add origin <github-uri>
git push -u --force origin master

And then, if you get the message:

remote: GitLab: You are not allowed to force push code to a protected branch on this project.

It's meaning your master had been protected, go to settings chick Repository and you will see the view below.

https://ithelp.ithome.com.tw/upload/images/20181115/20112288kd6mgkx5Vt.jpg

Find the master and choose Unprotect.

https://ithelp.ithome.com.tw/upload/images/20181115/20112288yLN9KIM5Ry.jpg

Then, try to push again if it can work your will only see the commit 'Initial commit' on your history.

https://ithelp.ithome.com.tw/upload/images/20181115/20112288kEoGX7lmJ4.jpg

Finally, remember to protect master if you success to delete history.

https://ithelp.ithome.com.tw/upload/images/20181115/20112288MMZiWgi6I7.jpg


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言